/*
      _______________________
     /      RET MAIN  +12    \
    |________________________ |
    |          EBP    +8      |    _______
    |________________________ |   /       \
    |          si     +4      |  |   ESP   |
    |________________________ |   \_______/ 
    |     RET getStackInfo    |_______|
    |________________________ |
    |                         |
    |________________________ |
    |                         |
    |________________________ |
    |                         |
    |________________________ |
    |                         |
    \________________________/


*/

.intel_syntax noprefix
.name getStackInfo
.global getStackInfo, _getStackInfo

 getStackInfo:
_getStackInfo: 
  
   // 001 -> calc. da stackFrameSize 
   mov eax, ebp
   mov ecx, esp
   sub eax, ecx
   push ebx
   mov ebx, eax
   
   // 002 -> reserve in heap sizeof(StackInfo_t) == 8 bytes
   push 8
   call _malloc
   add esp, 4
       
   // 003 -> calc. ret. address
   mov ecx, eax
   mov eax, ebp
   add eax, 4
   mov [ecx], eax 
   
   // 004 -> calc. stackFrameSize
   add ecx, 4
   mov [ecx], ebx
   
   mov eax, ecx
   sub eax, 4
   
   pop ebx
  
   ret
